from django.urls import path
from rest_framework.routers import DefaultRouter

from drfstudy.views import StudentViewSet, ClassViewSet

urlpatterns = [
    # {"get":"list"} get请求方式请求的地址为students/，会调用StudentViewSet里面的list方法
    # path('students/', StudentViewSet.as_view({"get": "list", "post": "create"})),
    # path('students/<pk>/', StudentViewSet.as_view({"get": "retrieve","put":"update","delete":"destory"})),

]
#实例化路由器对象
router = DefaultRouter()
#通过对象注册路由
#生成的也是一个列表
router.register('students', StudentViewSet) #参数 路由名，视图集类名
router.register('classes', ClassViewSet)
urlpatterns += router.urls
#把路由器生成的路由地址合并到urlpatterns列表中